package club.banyuan.demo.demo7;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author edz
 * @version 1.0
 * @date 2020/12/22 下午5:02
 */
public class ReflectDemo1 {
    public static void main(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<?> c = Class.forName("club.banyuan.demo.demo7.Student");

        //获取非公有的构造方法
        Constructor<?> dc = c.getDeclaredConstructor(String.class);

        //需要暴力反射，值为ture，取消访问检查
        dc.setAccessible(true);
        Object cc = dc.newInstance("陈聪");
        System.out.println(cc);
        //IllegalAccessException非法访问异常



    }
}
